<?php
class ml_biz_tag
{
    public function __construct(){
        
    }
    public function getyoulike($tags, $rid, $catelog=null){
        $catelog = empty($catelog) ? 'guang' : $catelog;
        $oRdsTag = new ml_model_guang_rdsTag();
        $tags_array = array();
        $tags_cnt = 0;
        if(is_array($tags)){
            foreach($tags as $tag){
                $tag_hash = ml_tool_resid::str_hash($tag);
                if($pt = $oRdsTag->getTagPt($tag_hash)){
                    $tags_array[$tag] = $pt;
                    $tags_cnt++;
                }
            }
            arsort($tags_array);
            $tags_array = array_keys($tags_array);
            shuffle($tags_array);
            $tags_array = array_slice($tags_array, 0 , 3);
        }
        
        /*
        if($tags_cnt<6){
            //$pad_array = $oRdsTag->get_taghot(0, 5, $catelog);
            
            $pad_array = array_diff($pad_array, $tags_array);
            $pad_cnt = 6 - $tags_cnt;
            $tags_array = array_merge($tags_array, array_slice($pad_array, 0, $pad_cnt));
        }
         */
        
        $goods_array = array();
        $rids = array();
        //$data = ml_tool_getdata::mlJsonData('gft_'.$catelog, 'hottaggoods');
        foreach($tags_array as $tag){
            $option['tag'] = array($tag);
            $oGuang = new ml_biz_guang();
            $oGuang->check($option);
            $content = $oGuang->main();
            foreach ($content['rows'] as $k => $value) {
                if($value['rid'] == $rid)
                    unset($content['rows'][$k]);

                //不重复
                if(isset($rids[$value['rid']]))
                    unset($content['rows'][$k]);
                else
                    $rids[$value['rid']] = 1;
            }

            $goods = array_filter( array_slice($content['rows'], 0,5));
            if(count($goods)>2)
                $aTag2Goods[$tag] = $goods;
            
        }
        
        return $aTag2Goods;
    }    
}
